//==============================渲染函数
function render(data) {
    let str = ``
    str = data.list.map((item, index) => {
        return `<tr>
                        <td>${item.email}</td>
                        <td>${item.name}</td>
                        <td>${item.phone}</td>
                        <td>${item.inngroup}</td>
                        <td>${item.isadmin ? "是" : "否"}</td>
                        <td>${item.status ? `<button>正常</button>` : `<button class="active">异常</button>`}</td>
                        <td>
                            <span class="iconfont icon-bianji"></span>
                            <span class="iconfont icon-shanchu"></span>
                        </td>
                    </tr>`
    }).join('')
    document.querySelector('tbody').innerHTML = str;
}


//===========================翻页功能
//获取上一页，下一页按钮
const buts = document.querySelectorAll('.box main .btn button')
// 设置初始请求参数
let page = 1;
let count = 10;
//======给按钮绑定点击事件，发送ajax请求，传参数
buts[0].onclick = () => {
    page <= 1 ? page = 1 : page--
    axios.get('/user/list', { params: { page: page, count: count } }).then((res) => {
        render(res.data)
    })
}
buts[1].onclick = () => {
    page++
    axios.get('/user/list', { params: { page: page, count: count } }).then((res) => {
        render(res.data)
    })
}


//========================搜索按钮功能
// 获取搜索按钮
const searchBtn = document.querySelector('.box .search button')
// 获取输入框按钮
const inputEle = document.querySelector('.box .search input')
//给button按钮设置点击事件，发送请求，获取数据
searchBtn.onclick = () => {
    axios.get('/user/search', { params: { searchkey: inputEle.value } }).then((res) => {
        render(res.data)
    })
}
